#include <stdio.h>
#include <stdlib.h>


typedef struct node{
	struct node* next;
	int val;
}node_t;


node_t list_arr[4];


node_t* init_list2(int size)
{
	int i = 0;

	// create haad node and init it
	node_t* head = malloc(sizeof(node_t));
	node_t* cur_node = head;
	
	cur_node->val  = 1;
	cur_node->next = NULL;

	head = cur_node;
	
	for(i = 1;i<size;i++)
	{
		node_t* node = malloc(sizeof(node_t));
		node->val = i + 1;
		node->next = NULL;

		cur_node->next = node;
		cur_node = node;
	}

	return head;
}



node_t* init_list(node_t *head,int size)
{
	if(NULL == head)
		return NULL;

	int i;
	node_t* headtmp = head;
	
	for(i=0;i<size;i++)
	{
		printf("%d,",(i+1));
		head->val = (i+1);
		head->next = head + 1;
		head++;
	}
	printf("\n");

	(headtmp + size - 1)->next = NULL;

	return headtmp;
}

void reverst_list(node_t *head)
{
	while(head)
	{
		printf("%d,",head->val);
		head = head->next;
	}
}

int main()
{

	printf("static \n");
	node_t *head = init_list(list_arr,4);
	reverst_list(head);

	printf("malloc \n");
	node_t *head2 = init_list2(4);
	reverst_list(head2);
	
	return 0;
}
